//
//  DolphinViewController.m
//  Dolphin
//
//  Created by Handymood on 11-6-22.
//  Copyright 2011 __Hanydmood__. All rights reserved.
//

#import "DolphinViewController.h"
#import "UIImageLayer.h"

#define CVC_VIEW_TAG		999

@implementation DolphinViewController

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    become_active_flag = FALSE;
    cur_id = 0;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"flow_center_hit" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"trigger_video" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"PAGE_ID" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"SHIFT_TO_PAGE" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"INNTER_SHIFT" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"shift_to_main_page" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"return_to_page_6" object:Nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"vr1" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"vr51" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"vr52" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"vr53" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"vr54" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"vr55" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"vr56" object:Nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"danti1" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"danti2" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"danti3" object:Nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i1" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i2" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i3" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i4" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i5" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i6" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i7" object:Nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i1n" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i2n" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i3n" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i4n" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i5n" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i6n" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i7n" object:Nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i1_10" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i2_11" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i3_12" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i4_14" object:Nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i1zw" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i1zwsj" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i1cw" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i1sf" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i1kt" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i1wsj" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i1cf" object:Nil];
 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i2zws" object:Nil];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i2cs" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i2etf" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i2kt" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i2ct" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i2sf" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i2cws" object:Nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i3wc" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i3girl" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i3zw" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i3kt1" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i3cf" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i3ct" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i3xg" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i3kt" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i3sf" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i3boy" object:Nil];
        
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i5kt" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i5yc" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i5yyc" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i6cf" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i6ct" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i6kt" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i6xg" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i7zw" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"6i7zwsj" object:Nil];
    /*
    zw 
    zwsj  
    cw  
    sf  
    kt  
    wsj  
    cf   
     
     6i2zws
     6i2cs
     6i2etf
     6i2kt
     6i2ct
     6i2sf
     6i2cws
     
     6i3wc
     6i3girl
     6i3zw
     6i3kt1
     6i3cf
     6i3ct 
     6i3xg
     6i3kt
     6i3sf
     6i3boy
    */
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(applicationWillResignActive:)
                                                 name:UIApplicationWillResignActiveNotification 
                                               object:NULL];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) 
                                                 name:UIApplicationWillTerminateNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) 
                                                 name:UIApplicationDidBecomeActiveNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground:) 
                                                 name:UIApplicationWillEnterForegroundNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) 
                                                 name:UIApplicationDidEnterBackgroundNotification object:nil];
    
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];
    curInterfaceOrientation = UIInterfaceOrientationPortrait;
    
    [self bookGen];
    
    theDoor = [[Door alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
    [self.view addSubview:theDoor];
    
    theBlackBg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
    theBlackBg.backgroundColor = [UIColor blackColor];
    
    threeLoadingPage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
    [threeLoadingPage setImage:[UIImage imageNamed:@"loading.png"]];
    threeLoadingPage.userInteractionEnabled = YES;
    [self.view addSubview:threeLoadingPage];
    threeLoadingPage.hidden = TRUE;
    
    sndEffect = [[SimpleAudioPlayer alloc] initWithFrame:CGRectMake(2000, 2000, 100, 100)];
    [sndEffect initAudioPlayer:@"click.mp3" autoPlay:FALSE isLoop:FALSE isButtonShow:FALSE];
}

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    
}

-(void) bookGen
{ 
    if(mediaBook)
    {
        [mediaBook reset];
        [mediaBook removeFromSuperview];
        [mediaBook release];
    }

    mediaBook = [[MediaBook alloc] init];
    
    //multiple layer demo
    [mediaBook initBook:@"default_gallery.xml" suffix:@"default" curOrientation:curInterfaceOrientation];
    mediaBook.hidden = TRUE;
    [self.view addSubview:mediaBook];
    
    menu = [[MediaBook alloc] init];
    [menu initBook:@"menu.xml" suffix:@"menu" curOrientation:UIInterfaceOrientationLandscapeRight];
    menu.frame = CGRectMake(0, 675, 1024, 768);
    [self.view addSubview:menu];
    
    LayerInfo *layerInfo= [[LayerInfo alloc] init];

    layerInfo.type =  @"img";
    layerInfo.resPath = @"blank.png";
    layerInfo.x = 0;
    layerInfo.y = 0;
    layerInfo.ani = 1;
    layerInfo.aniprefix = @"guang";
    layerInfo.anistartindex = 1;
    layerInfo.discrete = 2;
    layerInfo.aniendindex = 50;
    layerInfo.anisuffix = @".png";
    layerInfo.aniduration = 1.5;
    layerInfo.anirepeat = 0;
    
    bubble = [[UIImageLayer alloc] init];
    bubble.userInteractionEnabled = FALSE;
    [bubble initImage:@"blank.png" useOriginalSize:TRUE ratioMode:0 layerInfo:layerInfo];
    bubble.frame = CGRectMake(184, 616, bubble.frame.size.width, bubble.frame.size.height);
    [self.view addSubview:bubble];
    
    //in front of video
    loadingPage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
    [loadingPage setImage:[UIImage imageNamed:@"0.png"]];
    loadingPage.userInteractionEnabled = NO;
    [self.view addSubview:loadingPage];
    
    //update data slideshow by when hit album unit
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"update_slideshow" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:@"exit_button_trigger" object:Nil];
    
     float kTimerInternal = 0.5f;//0.075f;
     count = 0;
     objQueMagTimer = [NSTimer scheduledTimerWithTimeInterval: kTimerInternal target:self selector:@selector(timeCountProc) userInfo:nil repeats:YES]; 
    
    exitButton = [[UIImageLayer alloc] initWithFrame:CGRectMake(885,597,99, 39)];
    [exitButton initImage:@"exit_btn.png" useOriginalSize:TRUE ratioMode:TRUE layerInfo:Nil];
    [exitButton initHitMsg:@"exit_button_trigger"];
    [self.view addSubview:exitButton];
    exitButton.hidden = TRUE;
    
    threeDLoading = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
    [threeDLoading setImage:[UIImage imageNamed:@"threed_loading.png"]];
    threeDLoading.alpha = 0.0f;
    //[self.view addSubview:threeDLoading];
}

-(void) timeCountProc
{
    count++;
    
    if (count > 3) 
    {
        mediaBook.hidden = FALSE;
        loadingPage.hidden = TRUE;
        if(objQueMagTimer)
        {
            [objQueMagTimer invalidate];
            objQueMagTimer = Nil;
        }
        
        [theDoor openDoor];
    }
}


-(void)applicationWillResignActive:(UIApplication *)UIApplicationWillResignActiveNotification
{
    //timer stop code
    
    NSLog(@"application will resign active");
    
}

- (void)applicationWillTerminate:(UIApplication *)UIApplicationWillTerminateNotification
{
    NSLog(@"application will terminate");
}

- (void)applicationDidBecomeActive:(UIApplication *)UIApplicationDidBecomeActiveNotification
{
    NSLog(@"application did become active");
    if (become_active_flag) 
    {
        if (bgSnd != Nil) 
        {
            [bgSnd manuallyMusicOff];
            [bgSnd reset];
            [bgSnd release];
            bgSnd = Nil;
        }
        
        [self closeSpecialUI];
        [theDoor openDoor];
        
        cur_id = 0;
        [mediaBook shiftToPageId:0];
    }
    else
    {
        become_active_flag = TRUE;
    }

}

- (void)applicationWillEnterForeground:(UIApplication *)UIApplicationWillEnterForegroundNotification
{
    NSLog(@"Application Will Enter Foreground");
}

- (void)applicationDidEnterBackground:(UIApplication *)UIApplicationDidEnterBackgroundNotification 
{
    NSLog(@"Application Did Enter Background");
    if (bgSnd != Nil) 
    {
        [bgSnd manuallyMusicOff];
        [bgSnd reset];
        [bgSnd release];
        bgSnd = Nil;
    }
    
    [theDoor closeDoor];
    
    if (cur_id == 0) 
    {
        [mediaBook shiftToPageId:31];
    }
    
    //[mediaBook shiftToPageId:1];
}

-(void) notificationSelector:(NSNotification *) notification
{
    NSString *curNotificationName = [notification name];
    
    if ([curNotificationName isEqualToString:@"update_slideshow"])
    {
        NSString *path= [[NSString alloc] initWithString:[notification object]];
        
        if(mediaBook)
        {
            [mediaBook reset];
            [mediaBook removeFromSuperview];
            [mediaBook release];
        }
        
        mediaBook = [[MediaBook alloc] init];
                
        [mediaBook initBook:path suffix:@"default" curOrientation:curInterfaceOrientation];
        [self.view addSubview:mediaBook];
    }
    else if([curNotificationName isEqualToString:@"PAGE_ID" ])
    {
        if (bgSnd == Nil) 
        {
            bgSnd= [[SimpleAudioPlayer alloc] initWithFrame:CGRectMake(2000, 2000, 100, 100)];
            [bgSnd initAudioPlayer:@"bgm.mp3" autoPlay:TRUE isLoop:TRUE isButtonShow:FALSE];
        }

        exitButton.hidden = TRUE;
        [theDoor closeAndOpen];
        
        UIImageLayer *tempBtn =  [notification object];
        cur_id = tempBtn.button_id ;
        
        //[sndEffect mouseDownProcPause:Nil];
    }
    else if([curNotificationName isEqualToString:@"SHIFT_TO_PAGE" ])
    {
        [self closeSpecialUI];
        
        threeLoadingPage.hidden = TRUE;
        
        [mediaBook shiftToPageId:cur_id];
         bubble.frame = CGRectMake(184+(cur_id-1)*92, 616, bubble.frame.size.width, bubble.frame.size.height);
    }
    else if([curNotificationName isEqualToString:@"shift_to_main_page" ])
    {
        if (bgSnd != Nil) 
        {
            [bgSnd manuallyMusicOff];
            [bgSnd reset];
            [bgSnd release];
            bgSnd = Nil;
        }
        
        bgSnd= [[SimpleAudioPlayer alloc] initWithFrame:CGRectMake(2000, 2000, 100, 100)];
        [bgSnd initAudioPlayer:@"bgm.mp3" autoPlay:TRUE isLoop:TRUE isButtonShow:FALSE];
        
        [theDoor closeAndOpen]; 
        cur_id = 2;
    }
    else if([curNotificationName isEqualToString:@"vr1"] || 
              [curNotificationName isEqualToString:@"vr51"] || 
              [curNotificationName isEqualToString:@"vr52"] ||
              [curNotificationName isEqualToString:@"vr53"] || 
              [curNotificationName isEqualToString:@"vr54"] ||
              [curNotificationName isEqualToString:@"vr55"] || 
              [curNotificationName isEqualToString:@"vr56"] ||
            [curNotificationName isEqualToString:@"6i1zw"] || 
            [curNotificationName isEqualToString:@"6i1zwsj"] ||  
            [curNotificationName isEqualToString:@"6i1cw"] || 
            [curNotificationName isEqualToString:@"6i1sf"] ||  
            [curNotificationName isEqualToString:@"6i1kt"] ||  
            [curNotificationName isEqualToString:@"6i1wsj"] ||  
            [curNotificationName isEqualToString:@"6i1cf"] ||
            
            [curNotificationName isEqualToString:@"6i2zws"] ||
            [curNotificationName isEqualToString:@"6i2cs"] ||
            [curNotificationName isEqualToString:@"6i2etf"] ||
            [curNotificationName isEqualToString:@"6i2kt"] ||
            [curNotificationName isEqualToString:@"6i2ct"] ||
            [curNotificationName isEqualToString:@"6i2sf"] ||
            [curNotificationName isEqualToString:@"6i2cws"] ||
            
            [curNotificationName isEqualToString:@"6i3wc"] ||
            [curNotificationName isEqualToString:@"6i3girl"] ||
            [curNotificationName isEqualToString:@"6i3zw"] ||
            [curNotificationName isEqualToString:@"6i3kt1"] ||
            [curNotificationName isEqualToString:@"6i3cf"] ||
            [curNotificationName isEqualToString:@"6i3ct"] || 
            [curNotificationName isEqualToString:@"6i3xg"] ||
            [curNotificationName isEqualToString:@"6i3kt"] ||
            [curNotificationName isEqualToString:@"6i3sf"] ||
            [curNotificationName isEqualToString:@"6i3boy"] ||
            
            [curNotificationName isEqualToString:@"6i5kt" ] ||  
            [curNotificationName isEqualToString:@"6i5yc" ] ||  
            [curNotificationName isEqualToString:@"6i5yyc" ] ||  
            [curNotificationName isEqualToString:@"6i6cf" ] ||  
            [curNotificationName isEqualToString:@"6i6ct" ] ||  
            [curNotificationName isEqualToString:@"6i6kt"] ||  
            [curNotificationName isEqualToString:@"6i6xg" ] ||  
            [curNotificationName isEqualToString:@"6i7zw" ] ||  
            [curNotificationName isEqualToString:@"6i7zwsj"] 
    )
    {

        if (uiWebView != Nil) 
        {
            [uiWebView removeFromSuperview];
            [uiWebView release];
        }
        
        uiWebView  = [[UIWebView alloc] initWithFrame:CGRectMake(128,128, 768, 768)];
        [uiWebView loadRequest:[NSURLRequest requestWithURL : [NSURL fileURLWithPath:
                                                               [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:curNotificationName] isDirectory:NO]]];
        CGAffineTransform _transform = CGAffineTransformMakeScale(1.33,1.33);
        uiWebView.transform = _transform;
        
        [self.view addSubview:mediaBook];
        
        [self.view addSubview:theBlackBg];
        [self.view addSubview:uiWebView];
        
        [self.view addSubview:menu];
        [self.view addSubview:threeDLoading];
        threeDLoading.alpha = 1.0f;
        [UIView animateWithDuration:1.0f 
                              delay:2.0f 
                            options:UIViewAnimationCurveEaseOut 
                         animations:^{
                             threeDLoading.alpha = 0.0f;
                         }
                         completion:NULL];
        [self.view addSubview:bubble];
        [self.view addSubview:exitButton];
        [self.view addSubview:theDoor];
        
        exitButton.hidden = FALSE;

    }
    else if(([curNotificationName isEqualToString:@"danti1"] || 
                [curNotificationName isEqualToString:@"danti2"] ||
                [curNotificationName isEqualToString:@"danti3"]) &&  _360Map == Nil)
    {
        if (_360Map == Nil) 
        {
            _360Map = [[Three60Map alloc] initWithFrame:CGRectMake(0, 0, 1280, 768)];
            [self.view addSubview:_360Map];
        }
        
        if ([curNotificationName isEqualToString:@"danti1"]) 
        {
            [_360Map setPictureArrayMid:1 topEndIndex:37 midStartIndex:1 midEndIndex:37 bottomStartIndex:1 bottomEndIndex:37 prefix:@"41"];
        }
        else if([curNotificationName isEqualToString:@"danti2"])
        {
            [_360Map setPictureArrayMid:1 topEndIndex:36 midStartIndex:1 midEndIndex:33 bottomStartIndex:1 bottomEndIndex:36 prefix:@"42"];
        }
        else if([curNotificationName isEqualToString:@"danti3"])
        {
            [_360Map setRowNotJudge];
            [_360Map setPictureArrayOneRow:1 topEndIndex:36 prefix:@"danti02"];
        }
        
        [self.view addSubview:menu];
        [self.view addSubview:bubble];
        [self.view addSubview:exitButton];
        [self.view addSubview:theDoor];

        exitButton.hidden = FALSE;

    }
    else if([curNotificationName isEqualToString:@"6i1"] || 
               [curNotificationName isEqualToString:@"6i2"] || 
               [curNotificationName isEqualToString:@"6i3"] ||
               [curNotificationName isEqualToString:@"6i4"] ||
                [curNotificationName isEqualToString:@"6i5"] || 
                [curNotificationName isEqualToString:@"6i6"] ||
                [curNotificationName isEqualToString:@"6i7"])
    {
        [self setWithMsg:curNotificationName];
    }
    else if([curNotificationName isEqualToString:@"6i1_10"] || 
            [curNotificationName isEqualToString:@"6i2_11"] || 
            [curNotificationName isEqualToString:@"6i3_12"] || 
            [curNotificationName isEqualToString:@"6i4_14"])
    {
        NSString *fileNamePrefix = [curNotificationName  substringWithRange:NSMakeRange(0,3)];
        NSString *fileNameSuffix = [curNotificationName  substringWithRange:NSMakeRange([curNotificationName length]-2,2)];
        
        [mediaBook shiftToPageId:[fileNameSuffix intValue]];
        [self setWithMsg:fileNamePrefix];
    }
    else if([curNotificationName isEqualToString:@"6i1n"] || 
            [curNotificationName isEqualToString:@"6i2n"] || 
            [curNotificationName isEqualToString:@"6i3n"] ||
            [curNotificationName isEqualToString:@"6i4n"] ||
            [curNotificationName isEqualToString:@"6i5n"] || 
            [curNotificationName isEqualToString:@"6i6n"] ||
            [curNotificationName isEqualToString:@"6i7n"])
    {
        [self closeSpecialUI];
        
        if ([curNotificationName isEqualToString:@"6i1n"]) 
        {
            [mediaBook shiftToPageId:24];
        }
        else if ([curNotificationName isEqualToString:@"6i2n"]) 
        {
            [mediaBook shiftToPageId:25];
        }
        else if ([curNotificationName isEqualToString:@"6i3n"]) 
        {
            [mediaBook shiftToPageId:26];
        }
        else if ([curNotificationName isEqualToString:@"6i4n"]) 
        {
            [mediaBook shiftToPageId:27];
        }
        else if ([curNotificationName isEqualToString:@"6i5n"]) 
        {
            [mediaBook shiftToPageId:28];
        }
        else if ([curNotificationName isEqualToString:@"6i6n"]) 
        {
            [mediaBook shiftToPageId:29];
        }
        else if ([curNotificationName isEqualToString:@"6i7n"]) 
        {
            [mediaBook shiftToPageId:30];
        }
    }
    else if([curNotificationName isEqualToString:@"exit_button_trigger"] || 
               [curNotificationName isEqualToString:@"INNTER_SHIFT"])
    {
        [self closeSpecialUI];
    }
    else if([curNotificationName isEqualToString:@"return_to_page_6" ])
    {
        [mediaBook shiftToPageId:6];
    }
}

-(void) setWithMsg:(NSString *) thePrefix
{
    if (part6Wrapper != Nil) 
    {
        [part6Wrapper reset];
        [part6Wrapper removeFromSuperview];
        [part6Wrapper release];
        part6Wrapper = Nil;
    }
    
    int off_x = 20;
    int off_y = -40;

    int the_w = 850;
    int the_h = 850;
    
    if([thePrefix isEqualToString:@"6i1"])
    {
        off_x =10;
        off_y = -50;
    }
    else if ([thePrefix isEqualToString:@"6i4"]) 
    {
        off_x = 50;
        off_y = 130;
        the_w = 1000;
        the_h = 576;
    }
    
    part6Wrapper = [[Part6Wrapper alloc] initWithFrame:CGRectMake(20, 78, 985, 540)];
    [part6Wrapper setPictureArray:1 topEndIndex:20 prefix:thePrefix filetype:@"png" inWidth:the_w inHeight:the_h offX:off_x offY:off_y _name:thePrefix];
    
    NSString *smallImg = [[NSString alloc] initWithFormat:@"%@s.jpg",thePrefix];
    NSString *innerMsg = [[NSString alloc] initWithFormat:@"%@n",thePrefix];
    
    [part6Wrapper setSmallPicture:smallImg msg:innerMsg];
    [self.view addSubview:part6Wrapper];
    
    [self.view addSubview:menu];
    [self.view addSubview:bubble];
    [self.view addSubview:exitButton];
    [self.view addSubview:theDoor];
}

-(void) closeSpecialUI
{
    exitButton.hidden = TRUE;
    
    if (uiWebView != Nil) 
    {
        [uiWebView removeFromSuperview];
        [uiWebView release];
        [theBlackBg removeFromSuperview];
        
        uiWebView = Nil;
    }
    
    if (_360Map != Nil) 
    {
        [_360Map reset];
        [_360Map removeFromSuperview];
        [_360Map release];
        
        _360Map = Nil;
    }
    
    if (part6Wrapper != Nil) 
    {
        [part6Wrapper reset];
        [part6Wrapper removeFromSuperview];
        [part6Wrapper release];
        part6Wrapper = Nil;
    }
}

- (void)viewDidUnload
{
    if(mediaBook)
    {
        [mediaBook reset];
        [mediaBook removeFromSuperview];
        [mediaBook release];
    }
    
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (!mediaBook) 
    {
        return FALSE;
    }
 
    if(interfaceOrientation == UIInterfaceOrientationPortrait || 
       interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        mediaBook.curOrientationView = @"v";
    }
    else
    {
        mediaBook.curOrientationView = @"h";
    }
    
    if([mediaBook.gDataSet.align isEqualToString: @"v"])
    {
        if(interfaceOrientation == UIInterfaceOrientationPortrait || 
           interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
        {
            [mediaBook layoutAdjustWithOrientation:interfaceOrientation orientaionType:mediaBook.gDataSet.align];
            curInterfaceOrientation = interfaceOrientation;
            return YES;
        }
        else
        {
            return NO;
        }
    }
    else if([mediaBook.gDataSet.align isEqualToString: @"h"])
    {
        if(interfaceOrientation == UIInterfaceOrientationLandscapeRight || 
           interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
        {
            [mediaBook layoutAdjustWithOrientation:interfaceOrientation orientaionType:mediaBook.gDataSet.align];
            curInterfaceOrientation = interfaceOrientation;
            return YES;
        }
        else
        {
            return NO;
        }
    }
    else if([mediaBook.gDataSet.align isEqualToString: @"g"])
    {
        [mediaBook layoutAdjustWithOrientation:interfaceOrientation orientaionType:mediaBook.gDataSet.align];
        curInterfaceOrientation = interfaceOrientation;
        return YES;
    }
    else
    {
        mediaBook.preOrientation = interfaceOrientation;
        return NO;
    }
}

@end
